//
//  ParticularsViewController.m
//  TravelFollowYourHeart
//
//  Created by 鲁万玺 on 2017/12/19.
//  Copyright © 2017年 Lwx. All rights reserved.
//

#import "ParticularsViewController.h"
#import "ParticularsHeadView.h"
#import "ParticularsTableViewHeader.h"
#import "ParticularsOneTableViewCell.h"
#import "ParticularTwoTableViewCell.h"
#import "EvaluationViewController.h"
#import "ImmediateEvaluationViewController.h"


@interface ParticularsViewController ()<UITableViewDelegate,UITableViewDataSource,UINavigationControllerDelegate,ParticularsHeadViewDelegate>

@property (nonatomic, strong)UITableView *tableView;
@property (nonatomic, strong)ParticularsHeadView *headView;
@property (nonatomic, strong)UIView *footView;

@end

@implementation ParticularsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setUI];
    self.navigationController.delegate = self;
}

- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    if (!self.navigationController.delegate)
    {
        self.navigationController.delegate = self;
    }
}

- (void)setUI
{
    self.tableView = [[UITableView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT) style:UITableViewStylePlain];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    self.tableView.showsVerticalScrollIndicator = NO;
    self.tableView.tableHeaderView = self.headView;
    self.tableView.tableFooterView = self.footView;
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ParticularsOneTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([ParticularsOneTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ParticularTwoTableViewCell class]) bundle:nil] forCellReuseIdentifier:NSStringFromClass([ParticularTwoTableViewCell class])];
    [self.tableView registerNib:[UINib nibWithNibName:NSStringFromClass([ParticularsTableViewHeader class]) bundle:nil] forHeaderFooterViewReuseIdentifier:NSStringFromClass([ParticularsTableViewHeader class])];
    [self.view addSubview:self.tableView];
    
    if (@available(iOS 11.0, *)) {
        self.tableView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
    }else {
        self.automaticallyAdjustsScrollViewInsets = NO;
    }
}

- (ParticularsHeadView *)headView
{
    if (!_headView)
    {
         _headView =  [[[NSBundle mainBundle] loadNibNamed:@"ParticularsHeadView" owner:nil options:nil] firstObject];
        _headView.frame = CGRectMake(0, 0, SCREEN_WIDTH, 535);
        _headView.delegate = self;
    }
    return _headView;
}

- (UIView *)footView
{
    if (!_footView)
    {
        _footView = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 180)];
        
        UIButton *moreBtn = [[UIButton alloc]initWithFrame:CGRectMake(0, 0, 200, 30)];
        moreBtn.centerX = SCREEN_WIDTH/2;
        moreBtn.titleLabel.font = DEF_FontSize_13;
        [moreBtn setTitle:@"更多2条评论" forState:UIControlStateNormal];
        [moreBtn addTarget:self action:@selector(clickMoreBtn:) forControlEvents:UIControlEventTouchUpInside];
        [moreBtn setTitleColor:[UIColor darkGrayColor] forState:UIControlStateNormal];
        [_footView addSubview:moreBtn];
        
        UIButton *btn = [[UIButton alloc]initWithFrame:CGRectMake(0, CGRectGetMaxY(moreBtn.frame) +10, 150, 25)];
        btn.centerX = SCREEN_WIDTH/2;
        [btn setTitleColor:[UIColor themeColor] forState:UIControlStateNormal];
        [btn setTitle:@"我要评论" forState:UIControlStateNormal];
        [btn addTarget:self action:@selector(clickWantPL:) forControlEvents:UIControlEventTouchUpInside];
        [btn setCornerRadius: 25.0/2];
        [btn setBorderWidth:0.5 borderColor:[UIColor themeColor]];
        btn.titleLabel.font = DEF_FontSize_14;
        [_footView addSubview:btn];
        
        UIImageView *imageView = [[UIImageView alloc]initWithFrame:CGRectMake(20, CGRectGetMaxY(btn.frame) +10, SCREEN_WIDTH -40, 180 -10 -10 -CGRectGetMaxY(btn.frame) -10)];
        imageView.image = [UIImage imageNamed:@"img_userbg"];
        [_footView addSubview:imageView];
        
    }
    return _footView;
}

#pragma mark - UINavigationControllerDelegate
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
    BOOL isHomePage = [viewController isKindOfClass:[self class]];
    [self.navigationController setNavigationBarHidden:isHomePage animated:YES];
}

#pragma mark -UITableViewDelegate,UITableViewDataSource
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 2;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 2;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 0)
    {
        ParticularsOneTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ParticularsOneTableViewCell class])];
        return cell;
    }
    ParticularTwoTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:NSStringFromClass([ParticularTwoTableViewCell class])];
    return cell;
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    ParticularsTableViewHeader *view = [tableView dequeueReusableHeaderFooterViewWithIdentifier:NSStringFromClass([ParticularsTableViewHeader class])];
    if (section == 0)
    {
        view.titleLabel.text = @"套餐预定";
    }
    else
    {
        view.titleLabel.text = @"游客评价";
    }
    return view;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (indexPath.section == 1)
    {
        return 130;
    }
    return 44;
}

#pragma mark - ParticularsHeadViewDelegate
- (void)clickBackBtn
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)clickseeOrClearBtn
{
    
}

- (void)clickCallBtn
{
    
}

- (void)clickMoreBtn:(UIButton *)sender
{
    EvaluationViewController *vc = [[EvaluationViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

- (void)clickWantPL:(UIButton *)sender
{
    ImmediateEvaluationViewController *vc = [[ImmediateEvaluationViewController alloc]init];
    [self.navigationController pushViewController:vc animated:YES];
}

@end
